<template>
    <div class="sidebar">
        <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
            text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                                <template slot="title">{{ subItem.title }}</template>
                                <el-menu-item v-for="(threeItem,i) in subItem.subs" :key="i" :index="threeItem.index">
                                    {{ threeItem.title }}
                                </el-menu-item>
                            </el-submenu>
                            <el-menu-item v-else :index="subItem.index" :key="subItem.index">
                                {{ subItem.title }}
                            </el-menu-item>
                        </template>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
    import bus from '../common/bus';
    export default {
        data() {
            return {
                collapse: false,
                items: [
                    // !用户
                    {
                       
                        icon: 'el-icon-date',
                        index: '1',
                        title: '用户',
                        subs: [
                            {
                                index: 'userMonitor',
                                title: ' 用户监测',
                            }, {
                                
                                index: 'userManage',
                                title: '用户管理',
                            }, {
                                index: 'usersManage',
                                title: '用户组管理',
                            },
                            {
                                index: 'usersPermissionManage',
                                title: '用户组权限管理',
                            }
                        ]
                    },
                    // !设备
                    {
                       
                        icon: 'el-icon-date',
                        index: '2',
                        title: '设备',
                        subs: [
                            {
                                index: 'equipmentMonitoring',
                                title: '设备监控',
                            }, {
                                
                                index: 'equipmentManage',
                                title: '设备管理',
                            }, {
                                
                                index: 'equipmentKeysManage',
                                title: '设备密钥管理',
                            }, {
                                index: 'equipmentGroupManage',
                                title: '设备组管理',
                            }, {
                                
                                index: 'equipmentTaskMonitoring',
                                title: '设备任务监测',
                            }, {
                                
                                index: 'equipmentTaskManage',
                                title: '设备任务管理',
                            }
                        ]
                    },
                    // !文件
                    {
                       
                        icon: 'el-icon-date',
                        index: '3',
                        title: '文件',
                        subs: [
                            {
                                index: 'fileMonitoring',
                                title: '文件监控',
                            }, {
                                
                                index: 'fileManage',
                                title: '文件管理',
                            }
                        ]
                    },
                    // !系统
                    {
                       
                        icon: 'el-icon-date',
                        index: '4',
                        title: '系统',
                        subs: [
                            {
                                index: 'systemMonitoring',
                                title: '服务器监测',
                            }, {
                                
                                index: 'systemSetting',
                                title: '系统设置',
                            }, {
                                
                                index: 'distributedMonitoring',
                                title: '分布式监测',
                            }, {
                                
                                index: 'checkJournal',
                                title: '查看日志',
                            }, {
                                
                                index: 'accessControllerManage',
                                title: '访问控制器管理',
                            }, {
                                
                                index: 'agencyIpManage',
                                title: '代理IP管理',
                            }, {
                                
                                index: 'backupRestore',
                                title: '备份和还原',
                            }
                        ]
                    },
                    // !消息
                    {
                       
                        icon: 'el-icon-date',
                        index: '5',
                        title: '消息',
                        subs: [
                            {
                                index: 'infoMonitoring',
                                title: '消息监测',
                            }, {
                                
                                index: 'infoManage',
                                title: '消息管理',
                            }, {
                                
                                index: 'infoRelease',
                                title: '系统消息发布',
                            }
                        ]
                    },
                ]
            }
        },
        computed:{
            onRoutes(){
                return this.$route.meta.belong;
            }
        },
        created(){
            // 通过 Event Bus 进行组件间通信，来折叠侧边栏
            bus.$on('collapse', msg => {
                this.collapse = msg;
            });
        }
    }
</script>

<style scoped>
    .sidebar{
        display: block;
        position: absolute;
        left: 0;
        top: 70px;
        bottom:0;
        overflow-y: scroll;
    }
    .sidebar::-webkit-scrollbar{
        width: 0;
    }
    .sidebar-el-menu:not(.el-menu--collapse){
        width: 200px;
    }
    .sidebar > ul {
        height:100%;
    }
    .el-submenu .el-menu-item {
        height: 38px;
        line-height: 38px;
        font-size: 12px;
    }
</style>
